package com.application.metroscanner;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

import com.application.metroscanner.adapters.RideHistoryListAdapter;
import com.application.metroscanner.tools.FileManager;
import com.example.metroscanner.R;

public class RideHistoryActivity extends Activity {

	ListView rideHistory;

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ride_history);

		// Make sure we're running on Honeycomb or higher to use ActionBar APIs
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			// Show the Up button in the action bar.
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
		displayHistory();
	}

	/**
	 * Display ride history
	 */
	private void displayHistory() {
		rideHistory = (ListView) findViewById(R.id.rideHistory);
		FileManager fileManager = FileManager.getInstance(this);
		ArrayList<String> rideList = fileManager.ReadFile(getString(R.string.CSV_rides));

		// Create ArrayAdapter
		RideHistoryListAdapter listAdapter = new RideHistoryListAdapter(this, rideList);
		rideHistory.setAdapter(listAdapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

}
